package com.itec.learn.java.collections.list;

import java.util.*;
import java.util.concurrent.ConcurrentHashMap;

/**
 * @author chenyiqun
 */
public class LearnMap {

    public static void main(String[] args) {
        hashMap();
        linkedHashMap();
        synchronizedMap();
    }

    public static void hashMap(){
        System.out.println("=====================HashMap=====================");
        HashMap<String,String> hashMap = new HashMap<String, String>();
        hashMap.put("weqwe","A-1");
        hashMap.put("231rff","C-1");
        hashMap.put("ertgg","B-1");
        hashMap.put("5ttyyy", "F-1");
        hashMap.put("vgbggff", "Z-1");
        hashMap.put("rrtyujm", "Y-1");
        System.out.println(hashMap);
        Set<Map.Entry<String,String>> enrty = hashMap.entrySet();
        Iterator<Map.Entry<String,String>> iterator = enrty.iterator();
        while (iterator.hasNext()){
            System.out.println(iterator.next());
        }
    }


    public static void linkedHashMap(){
        System.out.println("=====================LinkedHashMap======================");
        LinkedHashMap<String,String> linkedHashMap = new LinkedHashMap<String, String>();
        linkedHashMap.put("A", "A-1");
        linkedHashMap.put("C", "C-1");
        linkedHashMap.put("B", "B-1");
        System.out.println(linkedHashMap);
    }

    public static void synchronizedMap(){
        System.out.println("=====================SynchronizedMap======================");
        Map<String,String> synchMap = Collections.synchronizedMap(new HashMap<String, String>());
        synchMap.put("A","AAA");
        synchMap.put("B","BBB");
        synchMap.put("C","CCC");
        synchMap.put("D","DDD");
        System.out.println(synchMap);
    }

    public static void concurrentHashMap(){
        System.out.println("=====================ConcurrentHashMap======================");
        ConcurrentHashMap<String,String> concurrentHashMap = new ConcurrentHashMap<String, String>();
        concurrentHashMap.put("A","AAA");
        concurrentHashMap.put("B","BBB");
        concurrentHashMap.put("C","CCC");
        concurrentHashMap.put("D","DDD");
        System.out.println(concurrentHashMap);
    }
}
